// 拿到所有动态路由数据
import { constantRoutes, asyncRoutes } from '@/router'
const state = {
  routes: []
}
const mutations = {
  setRoutes(state, data) {
    state.routes = [
      ...constantRoutes,
      ...data
    ]
  }
}
const actions = {
  filterRoutes(store, menus) {
    // 1. 当前用户的权限数据 (作为参数获取)
    // 2. 所有动态路由的列宾你
    // 3. 筛选当前用户拥有的权限
    const newAsyncRoutes = asyncRoutes
      .filter(item => menus.includes(item.name))
    console.log('vuex 筛选路由', newAsyncRoutes)
    store.commit('setRoutes', newAsyncRoutes)
    return newAsyncRoutes
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
